﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using DTO;
namespace DAO
{
   public class ATMDA
    {
       public static ATM GetByID(int maID)
       {
           ATM loai = null;
           SqlConnection cn = DataProvider.Connect();
           SqlCommand cmd = new SqlCommand("Proc_ATM_GetById", cn);
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.Add(new SqlParameter("@ma", maID));
           SqlDataReader dataReader = cmd.ExecuteReader();
           if (dataReader.Read())
           {
               loai = new ATM();
               loai.Ma = maID;
               loai.NgayMua = Convert.ToDateTime(dataReader["NgayMua"]);
               loai.GiaTien = Convert.ToSingle(dataReader["GiaTien"]);
               loai.ViTriDat = Convert.ToString(dataReader["ViTriDat"]);
               loai.MaTT = Convert.ToInt32(dataReader["MaTT"]);
           }
           cn.Close();
           return loai;
       }

       public static List<ATM> GetByMaTT(int maID)
       {
           List<ATM> lst = new List<ATM>();
           ATM loai = null;
           SqlConnection cn = DataProvider.Connect();
           SqlCommand cmd = new SqlCommand("Proc_ATM_GetByMaTT", cn);
           cmd.CommandType = CommandType.StoredProcedure;
           cmd.Parameters.Add(new SqlParameter("@maTT", maID));
           SqlDataReader dataReader = cmd.ExecuteReader();
           while (dataReader.Read())
           {
               loai = new ATM();
               loai.MaTT = maID;
               loai.NgayMua = Convert.ToDateTime(dataReader["NgayMua"]);
               loai.GiaTien = Convert.ToSingle(dataReader["GiaTien"]);
               loai.ViTriDat = Convert.ToString(dataReader["ViTriDat"]);
               loai.Ma = Convert.ToInt32(dataReader["Ma"]);
               lst.Add(loai);
           }
           cn.Close();
           return lst;
       }
    }
}
